import { _decorator, Label, Node, ProgressBar } from 'cc';
import { DEBUG } from 'cc/env';
import { ComponentExt } from 'db://cocos-ext/component/ComponentExt';

const { ccclass, property } = _decorator;

@ccclass('yy.Loading')
export class YYLoading extends ComponentExt {

    @property(ProgressBar)
    barProgess: ProgressBar = null;

    @property(Label)
    lbPrecent: Label = null;

    @property(Label)
    lbContent: Label = null;

    private _precent: number = 0;
    /** 当前百分比 */
    public get precent() {
        return this._precent;
    }
    public set precent(v: number) {
        this._precent = v;
        if (this.lbPrecent) {
            this.lbPrecent.string = (this._precent * 100 >> 0) + '%';
        }
        if (this.barProgess) {
            this.barProgess.progress = v;
        }
    }

    start() {

    }

    setProgress(loaded: number, total: number) {
        DEBUG && console.debug('precent:', loaded, total, loaded / total);
    }

}

